
describe("MoveToListController controller", function(){

    var controller = null;
    var objE = {errorCode:'code', errorMessage:'message'};

    beforeEach(function(){

        var t_alertCtrl = App.AlertController.create();
        var t_loadingCtrl = App.LoadingController.create();
        var t_moveHolderCtrl = App.MoveHolderController.create();
        App.MoveToListController.reopen({

            init:function(){
                this.set('controllers', Em.Object.create({
                    alert: t_alertCtrl,
                    loading: t_loadingCtrl,
                    moveHolder: t_moveHolderCtrl
                }));
            }
        });
        controller = App.MoveToListController.create();
    });

    it("prepareController", function(){
        var transfer = App.OwnAccountTransfer.create();

        spyOn(controller, 'showLoading');
        spyOn(controller, 'toListCallback');

        var toAccountList = [];
        spyOn(App.api_transfer,'fetchToListForTransfer').andCallFake(function(transfer, callback){
            callback(toAccountList,objE);
        });

        controller.prepareController();

        expect(controller.showLoading).toHaveBeenCalled();
        expect(controller.toListCallback).toHaveBeenCalled();
        expect(App.api_transfer.fetchToListForTransfer).toHaveBeenCalled();
    });

    it("isPayee not true", function(){
        var transfer = App.OwnAccountTransfer.create();
        expect(transfer.get('toPayee')).toBeFalsy();
    });

    it("isPayee - ThirdParty  should be true", function(){
        var transfer = App.ThirdPartyTransfer.create();
        expect(transfer.get('toPayee')).toBeTruthy();
    });

    it("isPayee - BillPayment  should be true", function(){
        var transfer = App.BillPayment.create();
        expect(transfer.get('toPayee')).toBeTruthy();
    });

    it("toListCallback", function(){

        spyOn(controller, 'hasError').andReturn(false);
        spyOn(controller, 'hideLoading');

        controller.toListCallback([], objE);

        expect(controller.hasError).toHaveBeenCalledWith(objE, false);
        expect(controller.hideLoading).toHaveBeenCalled();
    });
    it("selectListItem", function(){

        spyOn(controller,'setDestinationAccount');
        spyOn(controller, 'transitionTo');
        var account = App.BaseAccount.create();

        controller.selectListItem(account);

        expect(controller.setDestinationAccount).toHaveBeenCalledWith(account);
        expect(controller.transitionTo).toHaveBeenCalledWith('move.fromList');
    });

    it("setDestinationAccount - has been called", function(){

        spyOn(App.getSession(), 'getCurrentTransfer').andReturn(Ember.Object.create());
        controller.setDestinationAccount({});
        expect(App.getSession().getCurrentTransfer).toHaveBeenCalled();
    });

    it("setDestinationAccount - has been set with ThirdPartyPayee", function(){
        spyOn(App.getSession(), 'getCurrentTransfer').andReturn(App.ThirdPartyTransfer.create());
        var account = App.ThirdPartyPayee.create();
        controller.setDestinationAccount(account);
        var t_currentTransfer = App.getSession().getCurrentTransfer();
        expect(t_currentTransfer.get('payee')).toBe(account);
    });

    it("setDestinationAccount - has been set with HaveAccount", function(){
        spyOn(App.getSession(), 'getCurrentTransfer').andReturn(App.OwnAccountTransfer.create());
        var account = App.HaveAccount.create();
        controller.setDestinationAccount(account);
        var t_currentTransfer = App.getSession().getCurrentTransfer();
        expect(t_currentTransfer.get('toAccount')).toBe(account);
    });

    it("setDestinationAccount - has been called set BillPaymentPayee", function(){
        spyOn(App.getSession(), 'getCurrentTransfer').andReturn(App.BillPayment.create());
        var account = App.BillPaymentPayee.create();
        controller.setDestinationAccount(account);
        var t_currentTransfer = App.getSession().getCurrentTransfer();
        expect(t_currentTransfer.get('payee')).toBe(account);
    });

});